// pages/historyWrongQuestion/historyWrongQuestion.js
const api = require("../../api").API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '',
    list: [],
    current: 0,
    dailyProblemList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      date: options.date
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.wrongDetailList()
  },
  wrongDetailList() {
    let data = {
      userId: wx.getStorageSync('userId'),
      date: this.data.date
    }
    api.wrongDetailList(data).then(res => {
      if (res.code === '200') {
        this.setData({
          dailyProblemList: res.data
        })
      }
    })
  },
  collectSubmit() {
    let data = {
      userId: wx.getStorageSync('userId'),
      topicType: '1',
      topicId: this.data.dailyProblemList[this.data.current].topicId
    }
    api.collectSubmit(data).then(res => {
      if (res.code === '200') {
        wx.showToast({
          title: res.msg,
        })
        this.wrongDetailList();
      }
    })
  },
  collectCancel() {
    let data = {
      userId: wx.getStorageSync('userId'),
      topicType: '1',
      topicId: this.data.dailyProblemList[this.data.current].topicId
    }
    api.collectCancel(data).then(res => {
      if (res.code === '200') {
        wx.showToast({
          title: res.msg,
        })
        this.wrongDetailList();
      }
    })
  },
  analyz() {
    return wx.showToast({
      title: '此功能暂未开放...',
      icon: 'none'
    })
  },
  // 点击下一题按钮
  toNext() {
    // console.log(this.data.dailyProblemList[this.data.current].selected);
    if (this.data.current >= this.data.dailyProblemList.length - 1) {
      return
    }
    this.setData({
      current: this.data.current + 1
    })
  },
  // 点击上一题按钮
  toBefore() {
    if (this.data.current <= 0) {
      return
    }
    this.setData({
      current: this.data.current - 1
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})